home *** CD-ROM | disk | FTP | other *** search
- #include <string>
-
- #include "UAppleEventsMgr.h"
- #include "UExtractFromAEDesc.h"
- #include "AELib.h"
- #include "AEHandlers.h"
- #include "FileLib.h"
- #include "SendAEs.h"
-
- using namespace std;
-
- static Boolean GetAppProcess(OSType pCreator, ProcessSerialNumber *pProcess, FSSpec *pProcFile)
- {
- ProcessInfoRec sProcInfo;
- Boolean sFound = false;
-
- if (true /* gsHasProcessManager */) {
- pProcess->highLongOfPSN = 0;
- pProcess->lowLongOfPSN = kNoProcess;
- sProcInfo.processInfoLength = sizeof(ProcessInfoRec);
- sProcInfo.processName = nil;
- sProcInfo.processAppSpec = pProcFile;
- while ((!sFound) && (GetNextProcess(pProcess) == noErr)) {
- if (GetProcessInformation(pProcess, &sProcInfo) == noErr) {
- if (sProcInfo.processSignature == pCreator) {
- if ((sProcInfo.processType == 'APPL') ||
- (sProcInfo.processType == 'appe') ||
- (sProcInfo.processType == 'appc'))
- sFound = true;
- }
- }
- }
- if (!sFound) {
- pProcess->highLongOfPSN = 0;
- pProcess->lowLongOfPSN = kNoProcess;
- }
- }
- return(sFound);
- }
-
- static void BringAppToFront( OSType pCreator )
- {
- ProcessSerialNumber pProcess;
- FSSpec pProcFile;
- OSErr iErr;
-
- if ( GetAppProcess( pCreator, &pProcess, &pProcFile ) ) {
- iErr = SetFrontProcess( &pProcess );
- }
- }
-
-
- pascal OSErr HandleDoScript ( AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon )
- {
- #pragma unused ( reply, handlerRefcon )
-
- OSErr err= noErr;
-
- try {
- // get the PS data
- string psData;
- StAEDescriptor fdfDesc(*theAppleEvent, keyDirectObject);
- UExtractFromAEDesc::TheString(fdfDesc, psData);
-
- // save it out to a file
- FSSpec psOutFile;
- short fRefNum;
- OSErr err;
- err = FSMakeFSSpec( 0, 0, "\ppsTemp.ps", &psOutFile );
- err = FSpCreate( &psOutFile, 'R*ch', 'TEXT', smSystemScript );
- if ( !err ) {
- err = FSpOpenDF( &psOutFile, fsRdWrPerm, &fRefNum );
- if ( !err ) {
- long count = psData.length();
- FSWrite( fRefNum, &count, psData.c_str() );
- FSClose( fRefNum );
- }
- }
-
- // tell Distiller to process it (to a specific location)
- SendEventToProc ( &psOutFile, kCoreEventClass, kAEOpenDocuments, 'DSTL' );
-
- // tell Acrobat to open the PDF document
- // once it exists (and is no longer busy) of course!
- // and then bring Acro to front
- EventRecord theEvent;
- FSSpec pdfOutFile;
- err = FSMakeFSSpec( 0, 0, "\ppsTemp.pdf", &pdfOutFile );
- while ( !FileExists( &pdfOutFile ) ) WaitNextEvent( 0, &theEvent, 0, NULL );
- while ( FSpIsFileBusy( &pdfOutFile ) ) WaitNextEvent( 0, &theEvent, 0, NULL );
- SendEventToProc ( &pdfOutFile, kCoreEventClass, kAEOpenDocuments, 'CARO' );
- BringAppToFront( 'CARO' );
-
- // delete the temp file
- FSpDelete( &psOutFile );
- }
-
- catch (ExceptionCode inErr) {
- err = inErr;
- }
-
- return err;
- }
-